#!/bin/bash
# script modificado por msaito
pasta=./rssi_WiFi
N=1

if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

sleep 1
echo ""
echo "    WAI RSSI Maps Setup"
echo ""
echo "... 200 medidas/PM"
echo ""

while true
do
  echo "Insert a new number"
  read X

if [ $X != "" ]; then 
   N=$X
else
  arquivo_ref=$pasta/nref

  if [ -r $arquivo_ref ]
  then
    N=`cat $arquivo_ref`
  else
    touch $arquivo_ref
    N=1
    echo $N > $arquivo_ref
  fi
fi



  echo "Medindo PM" $N

  arquivo=$pasta/$N.txt
  touch $arquivo



  i=0
  while [ $i -ne 200 ]
  do

    echo --------------- >> $arquivo
    echo $i >> $arquivo
    echo "PM["$N"] coleta n"$i
    iwlist wlan0 scan >> $arquivo
  
  i=`expr $i + 1`
  done
  
  echo "Fim da medicao do PM" $N
  echo ""
  N=`expr $N + 1`
  echo $N > $arquivo_ref


done

